package web.eshop.panels;

import org.apache.wicket.markup.html.tree.LinkTree;
import org.apache.wicket.spring.injection.annot.SpringBean;
import web.eshop.tree.BookmarkablePageLinkTree;
import web.eshop.tree.CategoryTreeModelContainer;

public class CategoryTreePanel extends ShopBasePanel {

    private LinkTree linkTree;
    @SpringBean
    CategoryTreeModelContainer categoryTreeModelContainer;

    public CategoryTreePanel(String id) {
        super(id);

        linkTree = new BookmarkablePageLinkTree("linkTree", categoryTreeModelContainer.createTreeModel());
        add(linkTree);
//        linkTree = new LinkTree("linkTree", categoryTreeModelContainer.createTreeModel()) {
//
//            @Override
//            protected void onNodeLinkClicked(Object node, BaseTreeMy tree, AjaxRequestTarget target) {
//                super.onNodeLinkClicked(node, tree, target);
//                Category mp = (Category) ((DefaultMutableTreeNode) node).getUserObject();
//                Map<String, Long> paramsMap = new HashMap<String, Long>();
//                paramsMap.put("0", mp.getId());
//                setResponsePage(MultipleProductsEshopPage.class, new PageParameters(paramsMap));
//            }
//              @Override
//             protected ResourceReference getCSS() {
//        return new CompressedResourceReference(CategoryTreePanel.class,
//		"res/base-tree.css");
//    }
//        };
//        linkTree.getTreeState().collapseAll();
//        linkTree.getTreeState().setAllowSelectMultiple(false);
//        linkTree.setLinkType(BaseTreeMy.LinkType.AJAX_FALLBACK);
//        linkTree.setRootLess(true);
//        add(linkTree);
    }

    public void setTreePanelVisible(boolean visibility) {
        linkTree.setVisible(visibility);
    }

    public LinkTree getLinkTree() {
        return linkTree;
    }
}
